//
//  TableViewCellstylezero.m
//  BAOASystem
//
//  Created by michael on 2018/1/25.
//  Copyright © 2018年 czd. All rights reserved.
//

#import "TableViewCellstylezero.h"
#import "CollectionViewCell1.h"
#import "CollectionViewCell2.h"
@implementation TableViewCellstylezero
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
  _view0 = [[UIView alloc]init];
    _view0.frame = CGRectZero;
       [self.contentView addSubview:_view0];
 _label = [[UILabel alloc]init];
    _label.frame = CGRectZero;
        _label.numberOfLines = 0;
      [_label setFont:[UIFont systemFontOfSize:14]];
       [self.view0 addSubview:_label];
    _view = [[UIView alloc]init];
    _view.frame = CGRectZero;
       [self.view0 addSubview:_view];
    
  _view2 = [[UIView alloc]init];
    _view2.frame = CGRectZero;
       [self.contentView addSubview:_view2];
    
        self.collectionView.frame = CGRectMake(0, 40, KScreenWidth,((KScreenWidth-40-1)/2+60)*3+2);

 [self.contentView addSubview:self.collectionView];

}

return self;

}
-(void)setDic:(NSDictionary *)dic{
[self.collectionView reloadData]; //重新换数据源的时候 记得重回用的cell上的
_dic = dic;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 6;

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.row==0) {
     static NSString* cellId1 = @"CollectionViewCell1";
    CollectionViewCell1 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId1 forIndexPath:indexPath];
    
    cell.array = _dic[@"ctgTwoLevelShowList"];
    [cell layoutSubviews];
    return cell;
}else{

 static NSString* cellId2 = @"CollectionViewCell2";
    CollectionViewCell2 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId2 forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
   NSArray *array = _dic[@"ctgNewProductList"];
   cell.dic =array [indexPath.row-1];
   [cell layoutSubviews];
    return cell;
}
   
}
-(UICollectionView *)collectionView{
if (!_collectionView) {
  UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake((KScreenWidth-1)/2,((KScreenWidth-40-1)/2+60));

    layout.minimumLineSpacing = 1;
   layout.minimumInteritemSpacing = 1;
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth,((KScreenWidth-40-1)/2+60)*3+2) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    _collectionView.pagingEnabled = true;
//    _collectionView.scrollEnabled=NO;
    _collectionView.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];
//        _collectionView.backgroundColor = [UIColor whiteColor];

[_collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell1" bundle:nil] forCellWithReuseIdentifier:@"CollectionViewCell1"];
[_collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell2" bundle:nil] forCellWithReuseIdentifier:@"CollectionViewCell2"];
//self.collectionView.alwaysBounceVertical = YES;

    _collectionView.showsHorizontalScrollIndicator = false;
    
}
return _collectionView;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

NSLog(@"111");
if (indexPath.row ==0) {
    
}else{
   NSArray *array = _dic[@"ctgNewProductList"];
 NSDictionary *dic =array [indexPath.row-1];

shangpinxqViewController *vc = [[shangpinxqViewController alloc]init];
vc.pdid = dic[@"id"];
vc.hidesBottomBarWhenPushed = YES;
[self.ViewController.navigationController pushViewController:vc animated:YES];
}
}
- (void)layoutSubviews{
[super layoutSubviews];
  _view0.frame = CGRectMake(0, 0, KScreenWidth, 39);
    _view0.backgroundColor = [UIColor whiteColor];
_view2.frame = CGRectMake(0,_collectionView.bottom, KScreenWidth, 10);
    _view2.backgroundColor = [UIColor colorWithHexString:@"f0eff5"];

  _view.frame = CGRectMake(5, 10, 10, 20);
    _view.backgroundColor = [UIColor colorWithHexString:@"0AA0F6"];

 _label.frame = CGRectMake(_view.right+10,10, KScreenWidth-40, 20);
    _label.text  = _dic[@"ctgName"];
    _label.textColor = [UIColor blackColor];
   _label.font = [UIFont boldSystemFontOfSize:14];
 
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
